package com.typhoon.spring_boot_demo1.utils;

import com.typhoon.spring_boot_demo1.bean.Order;
import com.typhoon.spring_boot_demo1.bean.Refund;
import com.typhoon.spring_boot_demo1.bean.User;
import com.typhoon.spring_boot_demo1.constants.CommonSearchTypeEnum;
import com.typhoon.spring_boot_demo1.dto.SearchResultDto;

/**
 * 转换工具类
 *
 */
public class ConvertUtils {

public static SearchResultDto convertSearchResultDto(User user) {
    if(null == user) {
        return null;
    }
    SearchResultDto resultDto = new SearchResultDto();
    resultDto.setCode(user.getId().toString());
    resultDto.setName(CommonSearchTypeEnum.USER.name());
    resultDto.setUrl("http://localhost:8080/get/" + user.getId());
    return resultDto;
}

    /**
     * 将退款信息转换为通用结果
     *
     * @param refund
     * @return
     */
    public static SearchResultDto convertSearchResultDto(Refund refund) {
        if(null == refund) {
            return null;
        }
        SearchResultDto resultDto = new SearchResultDto();
        resultDto.setCode(refund.getRefundId().toString());
        resultDto.setName(CommonSearchTypeEnum.REFUND.name());
        resultDto.setUrl("http://localhost:8080/get/" + refund.getRefundId());
        return resultDto;
    }

    public static SearchResultDto convertSearchResultDto(Order order) {
        if(null == order) {
            return null;
        }
        SearchResultDto resultDto = new SearchResultDto();
        resultDto.setCode(order.getOrderId().toString());
        resultDto.setName(CommonSearchTypeEnum.ORDER.name());
        resultDto.setUrl("http://localhost:8080/get/" + order.getOrderId());
        return resultDto;
    }

}
